<?php 
error_reporting(E_ALL^E_NOTICE^E_WARNING);
	session_start();
	include_once("./commonality.php");
	if(!isset($_SESSION['account'])){
		tankuang("请登录","./register1.php");
		exit;
	}
$pid=$_GET['pid'];	
//判断颜色尺寸有没有值	
if(isset($_GET['sub'])){
	if(!isset($_GET['color']) || !isset($_GET['size'])){
		echo "<script>
		alert('请选择颜色和尺寸')
		location.href='show.php?pid=$pid'
		</script>";
	}
}	
$num=$_GET['num'];
$size=$_GET['size'];
$color=$_GET['color'];




if(!empty($_SESSION['cart'])){
	foreach($_SESSION['cart']  as $key=>$value){
		//重复购买加数量
		if($pid==$value['pid']){
			//tankuang("重复购买","./php8.1.php");
			$num=$value['num']+1;
			$_SESSION['cart'][$key]['num']=$num;
			tankuang("重复购买","./gouwuche.php");
			exit;
		}

	}
};
$num1=count($_SESSION['cart']);//增加之前的数量
$_SESSION['cart'][]=array("pid"=>$pid,"num"=>$num,"size"=>$size,"color"=>$color);
$num2=count($_SESSION['cart']);//增加之后的数量
if($num2-$num1>0){
	tankuang("添加成功","./gouwuche.php");
}else{
	tankuang("添加失败","show.php");
}




 ?>